package com.ruoyi.rpt.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rpt.domain.RptDesign;
import com.ruoyi.rpt.service.IRptDesignService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 报表设计Controller
 * 
 */
@RestController
@RequestMapping("/rpt/design")
public class RptDesignController extends BaseController
{
    @Autowired
    private IRptDesignService rptDesignService;
    
    /**
     * 获取报表设计信息
     */
    // @RequiresPermissions("rpt:design:query")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return success(rptDesignService.selectRptDesignByReportId(reportId));
    }
    
    /**
     * 保存报表设计
     */
    // @RequiresPermissions("rpt:design:edit")
    @Log(title = "报表设计", businessType = BusinessType.UPDATE)
    @PostMapping
    public AjaxResult save(@RequestBody RptDesign rptDesign)
    {
        return toAjax(rptDesignService.saveRptDesign(rptDesign));
    }
    
    /**
     * 获取报表设计历史版本
     */
    // @RequiresPermissions("rpt:design:history")
    @GetMapping(value = "/history/{reportId}")
    public TableDataInfo getHistory(@PathVariable("reportId") Long reportId)
    {
        startPage();
        List<RptDesign> list = rptDesignService.selectDesignHistory(reportId);
        return getDataTable(list);
    }
    
    /**
     * SQL预览
     */
    // @RequiresPermissions("rpt:design:preview")
    @PostMapping(value = "/preview")
    public AjaxResult previewSql(@RequestBody Map<String, Object> params)
    {
        return rptDesignService.previewSql(params);
    }
} 